package com.bawei.networkmoudle.uitls;

import android.content.Context;
import android.widget.ImageView;

import com.bawei.networkmoudle.R;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;


public class ImgUtils {

    public ImgUtils() {
    }
    private static ImgUtils instance;

    public static ImgUtils getInstance(){
        if (instance==null){
            instance = new ImgUtils();
        }
       return instance;
    }
    //普通加载
    public  void loadImage(Context context, String url, ImageView imageView) {
        RequestOptions options = new RequestOptions()
                .centerCrop()
                .placeholder(R.mipmap.ic_launcher)
                .error(R.mipmap.ic_launcher);
        Glide.with(context).load(url).apply(options).into(imageView);
    }
    /**
     * 加载圆形图片
     */
    public  void loadCircleImage(Context context, String url, ImageView imageView) {
        RequestOptions options = new RequestOptions()
                .circleCrop()
                .placeholder(R.mipmap.ic_launcher)
                .error(R.mipmap.ic_launcher);
        Glide.with(context).load(url).apply(options).into(imageView);
    }
    /**
     * 加载圆角图片
     */
    public  void loadRoundImage(Context context, String url, ImageView imageView) {
        RequestOptions options = RequestOptions
                .bitmapTransform(new RoundedCorners(20))
                .placeholder(R.mipmap.ic_launcher)
                .error(R.mipmap.ic_launcher);

        Glide.with(context).load(url).apply(options).into(imageView);
    }

}
